package com.gs.gaosheng.controller;

import com.gs.common.annotation.Log;
import com.gs.common.core.controller.BaseController;
import com.gs.common.core.domain.AjaxResult;
import com.gs.common.core.page.TableDataInfo;
import com.gs.common.enums.BusinessType;
import com.gs.common.utils.poi.ExcelUtil;
import com.gs.gaosheng.domain.GsCouponUser;
import com.gs.gaosheng.service.GsCouponUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 优惠券和用户关联表Controller
 *
 * @author yy
 * @date 2023-08-03
 */
@RestController
@RequestMapping("/gaosheng/couponuser")
public class GsCouponUserController extends BaseController
{
    @Autowired
    private GsCouponUserService gsCouponUserService;

    /**
     * 查询优惠券和用户关联表列表
     */
    @GetMapping("/list")
    public TableDataInfo list(GsCouponUser gsCouponUser)
    {
        startPage();
        List<GsCouponUser> list = gsCouponUserService.selectGsCouponUserList(gsCouponUser);
        return getDataTable(list);
    }

    /**
     * 导出优惠券和用户关联表列表
     */
    @Log(title = "优惠券和用户关联表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GsCouponUser gsCouponUser)
    {
        List<GsCouponUser> list = gsCouponUserService.selectGsCouponUserList(gsCouponUser);
        ExcelUtil<GsCouponUser> util = new ExcelUtil<GsCouponUser>(GsCouponUser.class);
        return util.exportExcel(list, "couponuser");
    }

    /**
     * 获取优惠券和用户关联表详细信息
     */
    @GetMapping(value = "/{couponUserId}")
    public AjaxResult getInfo(@PathVariable("couponUserId") Long couponUserId)
    {
        return AjaxResult.success(gsCouponUserService.selectGsCouponUserById(couponUserId));
    }

    /**
     * 新增优惠券和用户关联表
     */
    @Log(title = "优惠券和用户关联表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GsCouponUser gsCouponUser)
    {
        return toAjax(gsCouponUserService.insertGsCouponUser(gsCouponUser));
    }

    /**
     * 修改优惠券和用户关联表
     */
    @Log(title = "优惠券和用户关联表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GsCouponUser gsCouponUser)
    {
        return toAjax(gsCouponUserService.updateGsCouponUser(gsCouponUser));
    }

    /**
     * 删除优惠券和用户关联表
     */
    @Log(title = "优惠券和用户关联表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{couponUserIds}")
    public AjaxResult remove(@PathVariable Long[] couponUserIds)
    {
        return toAjax(gsCouponUserService.deleteGsCouponUserByIds(couponUserIds));
    }
}
